<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "user_package".
 *
 * @property string $id
 * @property string $package_id
 * @property string $user_id
 * @property integer $created_at
 * @property integer $updated_at
 */
class UserPackage extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_package';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['package_id', 'user_id', 'created_at', 'updated_at'], 'required'],
            [['package_id', 'user_id', 'created_at', 'updated_at'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'package_id' => '资产包ID',
            'user_id' => '用户ID',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }

    public function afterSave($insert, $changedAttributes)
    {
        // TODO: Change the autogenerated stub
        if (parent::afterSave($insert, $changedAttributes)) {
            if ($insert === false && !empty($changedAttributes)) {
                $this->created_at = Date('Y-m-d H:i:s', $this->created_at);
                $this->updated_at = Date('Y-m-d H:i:s', $this->updated_at);
            }
        }
    }
}
